<?php

namespace App\V3\V3_2_7\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use DateTimeInterface;
class CustomTagModel extends Model
{


    use HasFactory;
    protected $table   = 'custom_tag';
    protected $dateFormat = 'U';//这个时间字段被为被格式化为UNIX 时间戳的形式存储
    //toArray 时间转换问题
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }
    /**
     * $dates 数组内的列转换为日期格式
     *
     * @var array
     */
    protected $dates = [
        'create_time'
    ];
    static public function addCustomTag($data)
    {
        return CustomTagModel::insertGetId($data);
    }

    static public function updCustomTag($condition,$updData)
    {
        return CustomTagModel::where($condition)->update($updData);
    }
    static public function delCustomTag($condition)
    {
        return CustomTagModel::where($condition)->update(['delete_flag'=>1]);
    }
    static public function getCustomTagInfo($condition)
    {
        return CustomTagModel::select(
            'id',
            'color',
            'is_top',
            'main_id',
            'use_type',
            'label_name',
            'sort_number',
            'create_time'
            )
        ->where('delete_flag',0)->where($condition)->first();
    }
    static public function getCustomTagList($condition,$data)
    {
        return CustomTagModel::select('id','main_id','label_name','create_time')
        ->where($condition)
        ->where('delete_flag',0)
        ->orderBy('create_time', 'ASC')
        ->paginate($data['pageSize'], ['*'], '', $data['currentPage'])
        ->toArray();
    }
}
